//
//  AddressManagerViewController.m
//  StandardizedProduct
//
//  Created by 宁宁 on 16/7/25.
//  Copyright © 2016年 ym. All rights reserved.
//

#import "AddressManagerViewController.h"

#import "AddressTableViewCell.h"//地址Cell
#import "AddressModel.h"//地址Model

#import "AddNewAddressViewController.h"//添加新地址Controller

@interface AddressManagerViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;

@end

@implementation AddressManagerViewController

 static NSString *const AddressTableViewCellID = @"AddressTableViewCell";

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    //设置导航栏
    [self setNav];
    
    //添加新地址
    [self addNewAddress];
    
    //注册TableView
    [self registerTableView];
}
- (void)setNav{
    self.title = @"管理收货地址";
    UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(back)];
    self.navigationItem.leftBarButtonItem = back;
}
#pragma mark === 添加新地址 ===
- (void)addNewAddress{
    UIButton *addNewAddress = [UIButton buttonWithType:UIButtonTypeCustom];
    addNewAddress.frame = CGRectMake(0, SCREEN_HEIGHT - 50, SCREEN_WIDTH, 50);
    addNewAddress.backgroundColor = [UIColor lightGrayColor];
    [addNewAddress setTitle:@"添加新地址" forState:UIControlStateNormal];
    addNewAddress.titleLabel.font = [UIFont systemFontOfSize:16];
    [addNewAddress addTarget:self action:@selector(jumpToAddNewAddress) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:addNewAddress];
}

#pragma mark === 注册TableView ===
- (void)registerTableView{
    [self.tableView registerClass:[AddressTableViewCell class] forCellReuseIdentifier:AddressTableViewCellID];
}

#pragma mark === 注册TableView ===
//行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 5;
}
//行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 122;
}
//Reusable
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    AddressTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:AddressTableViewCellID];
    
    
    cell.selectionStyle = UITableViewCellStyleDefault;
    return cell;
}


#pragma mark === 跳转到添加新地址 ===
- (void)jumpToAddNewAddress{
    AddNewAddressViewController *addNew = [[AddNewAddressViewController alloc] init];
    [self.navigationController pushViewController:addNew animated:YES];
}

- (void)back{
    [self.navigationController popViewControllerAnimated:YES];
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView= [[UITableView alloc]initWithFrame:CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT - 64)style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
//        _tableView.separatorColor = RGBACOLOR(36, 34, 47, 1);
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = RGBACOLOR(36, 34, 47, 1);
        _tableView.showsVerticalScrollIndicator = NO;//去掉滑动竖条
        [self.view addSubview:_tableView];
    }
    return _tableView;
}
@end
